home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / hp150.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  455 lines

  1. /*
  2.  * The routines in this file provide support for HP150 screens
  3.  * and routines to access the Keyboard through KEYCODE mode.
  4.  * It compiles into nothing if not an HP150 screen device.
  5.  * added by Daniel Lawrence
  6.  */
  7.  
  8. #define    termdef    1            /* don't define "term" external */
  9.  
  10. #include        <stdio.h>
  11. #include        "estruct.h"
  12. #include    "edef.h"
  13.  
  14. #if     HP150
  15.  
  16. #define NROW    24                      /* Screen size.                 */
  17. #define NCOL    80                      /* Edit if you want to.         */
  18. #define    MARGIN    8            /* size of minimim margin and    */
  19. #define    SCRSIZ    64            /* scroll size for extended lines */
  20. #define    NPAUSE    15            /* # times thru update to pause */
  21. #define BEL     0x07                    /* BEL character.               */
  22. #define ESC     0x1B                    /* ESC character.               */
  23.  
  24. extern  int     openhp();               /* Forward references.          */
  25. extern  int     ttgetc();
  26. extern  int     ttputc();
  27. extern  int     ttflush();
  28. extern    int    hpflush();
  29. extern  int     closehp();
  30. extern    int    hp15kopen();
  31. extern    int    hp15kclose();
  32. extern  int     hp15move();
  33. extern  int     hp15eeol();
  34. extern  int     hp15eeop();
  35. extern  int     hp15beep();
  36. extern    int    gethpkey();
  37. extern    int    hp15rev();
  38. extern    int    hp15cres();
  39. #if    COLOR
  40. extern    int    hp15fcol();
  41. extern    int    hp15bcol();
  42. #endif
  43.  
  44. /* weird to ascii translation table */
  45.  
  46. char trans[][2] = {
  47.     0x24,    9,    /* tab */
  48.     0x25,    13,    /* ret */
  49.     0x27,    8,    /* backspace */
  50.     0x30,    48,    /* zero */
  51.     0x31,    49,    /* one */
  52.     0x32,    50,    /* two */
  53.     0x33,    51,    /* three */
  54.     0x34,    52,    /* four */
  55.     0x35,    53,    /* five */
  56.     0x36,    54,    /* six */
  57.     0x37,    55,    /* seven */
  58.     0x38,    56,    /* eight */
  59.     0x39,    57,    /* nine */
  60.     0x50,    13,    /* enter */
  61.     0x54,    27,    /* break -> ESC */
  62.     0x55,    27,    /* esc */
  63.     0x58,    24,    /* stop -> ^X */
  64.     0x70,    45,    /* N-minus */
  65.     0x71,    42,    /* N-asterisk */
  66.     0x72,    43,    /* N-plus */
  67.     0x73,    47,    /* N-slash */
  68.     0x74,    44,    /* N-comma */
  69.     0x75,    13,    /* N-enter */
  70.     0x76,    9,    /* N-tab */
  71.     0x77,    46    /* N-period */
  72. };
  73.  
  74. #define NTRANS    sizeof(trans) / 2
  75.  
  76. union REGS r;        /* register set for bios and dos (AGIOS) calls */
  77. int capslock = 0;    /* caps lock flag */
  78.  
  79. /*
  80.  * Standard terminal interface dispatch table. Most of the fields point into
  81.  * "termio" code.
  82.  */
  83. TERM    term    = {
  84.     NROW-1,
  85.         NROW-1,
  86.         NCOL,
  87.         NCOL,
  88.     MARGIN,
  89.     SCRSIZ,
  90.     NPAUSE,
  91.     openhp,
  92.         closehp,
  93.     hp15kopen,
  94.     hp15kclose,
  95.     gethpkey,
  96.         ttputc,
  97.         hpflush,
  98.         hp15move,
  99.         hp15eeol,
  100.         hp15eeop,
  101.         hp15beep,
  102.         hp15rev,
  103.         hp15cres
  104. #if    COLOR
  105.     , hp15fcol,
  106.     hp15bcol
  107. #endif
  108. };
  109.  
  110. hp15move(row, col)
  111. {
  112.         ttputc(ESC);
  113.         ttputc('&');
  114.         ttputc('a');
  115.         hp15parm(col);
  116.         ttputc('c');
  117.         hp15parm(row);
  118.         ttputc('R');
  119. }
  120.  
  121. hpflush()
  122.  
  123. {
  124.  
  125. }
  126.  
  127. hp15eeol()
  128. {
  129.         ttputc(ESC);
  130.         ttputc('K');
  131. }
  132.  
  133. hp15eeop()
  134. {
  135.         ttputc(ESC);
  136.         ttputc('J');
  137. }
  138.  
  139. hp15rev(status)        /* change the reverse video status */
  140.  
  141. int status;    /* TRUE = on, FALSE = off */
  142.  
  143. {
  144.     ttputc(ESC);
  145.     ttputc('&');
  146.     ttputc('d');
  147.     ttputc((status != FALSE) ? 'B': '@');
  148. }
  149.  
  150. hp15cres()    /* change screen resolution */
  151.  
  152. {
  153.     return(TRUE);
  154. }
  155.  
  156. hp15beep()
  157. {
  158.         ttputc(BEL);
  159.         ttflush();
  160. }
  161.  
  162. hp15parm(n)
  163. register int    n;
  164. {
  165.         register int    q;
  166.  
  167.         q = n/10;
  168.         if (q != 0)
  169.                 hp15parm(q);
  170.         ttputc((n%10) + '0');
  171. }
  172.  
  173. #if    COLOR
  174. hp15fcol()    /* we really can't do colors here, so just ignore it */
  175. {
  176. }
  177.  
  178. hp15bcol()    /* we really can't do colors here, so just ignore it */
  179. {
  180. }
  181. #endif
  182.  
  183. gethpkey()    /* get a key from the HP keyboard while in keycode mode */
  184.  
  185. {
  186.     static int keepflag = 0;    /* kept ahead char flag */
  187.     static int keepchar = 0;    /* kept ehead flag */
  188.     int c;
  189.     int devid;            /* device ID */
  190.     int ctype;            /* type of character gotten */
  191.     int shiftb;            /* state of shift keys */
  192.     int i;
  193.     
  194.     /* if we are in an extended char sequence, finish it */
  195.     if (keepflag != 0) {
  196.         keepflag = 0;
  197.         return(keepchar);
  198.     }
  199.  
  200.     /* grab the next 4 char sequence */
  201. next:    shiftb = ttgetc();
  202.     devid = ttgetc();
  203.     c = ttgetc();
  204.     ttgetc();        /* skip null byte */
  205.     
  206.     /* make sure we are from the keyboard */
  207.     if (devid != 192)
  208.         goto next;
  209.  
  210.     /* if normal ascii, return it */
  211.     if ((shiftb & 0x80) == 0) {
  212.         if (capslock && c >= 'a' && c <= 'z')
  213.             c -= 32;
  214.         return(c);
  215.     }
  216.  
  217.     /* check specifically for the caps lock key */
  218.     if (c == 0x56) {
  219.         capslock = ~capslock;
  220.         goto next;
  221.     }
  222.  
  223.     /* check to see if it needs translation */
  224.     for (i=0; i < NTRANS; i++)
  225.         if (trans[i][0] == c)
  226.             return((int)trans[i][1]);
  227.  
  228.     /* other wise, shove it in the keep char and return the leadin code */
  229.     keepchar = c;
  230.     keepflag = 1;
  231.     return(0);
  232. }
  233.  
  234. openhp()        /* open the HP150 screen for input */
  235.  
  236. {
  237.     strcpy(sres, "NORMAL");
  238.     revexist = TRUE;
  239. }
  240.  
  241. closehp()        /* close the HP150 screen for input */
  242.  
  243. {
  244. }
  245.  
  246. hp15kopen()        /* open the HP150 keyboard for input */
  247.  
  248. {
  249.     /* define key charectoristics with AGIOS call (0, 40) */
  250.     defkey();
  251.  
  252.     /* Turn on RAW mode with MSDOS call 44h */
  253.     rawon();
  254.  
  255.     /* Turn off Control-C checking  MS-DOS 33h */
  256.     ckeyoff();
  257.  
  258.     /* Turn on keycode mode with AGIOS call (0,43) */
  259.     keycon();
  260.  
  261.     /* display the application softkey labels */
  262.     dsplbls();
  263. }
  264.  
  265. hp15kclose()        /* close the HP150 keyboard for input */
  266.  
  267. {
  268.     /* define key charectoristics with AGIOS call (0, 40) */
  269.     undefkey();
  270.     
  271.     /* Turn off RAW mode with MSDOS call 44h */
  272.     rawoff();
  273.  
  274.     /* Turn on Control-C checking  MS-DOS 33h */
  275.     ckeyon();
  276.  
  277.     /* Turn off keycode mode with AGIOS call (0,43) */
  278.     keycoff();
  279. }
  280.  
  281. rawon()        /* put the HP150 keyboard into RAW mode */
  282.  
  283. {
  284.     /* get the IO control info */
  285.  
  286.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  287.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  288.     intdos(&r, &r);        /* go fer it */
  289.  
  290.     r.h.dh = 0;        /* clear high byte for put */
  291.     r.h.dl |= 0x20;        /* set raw bit */
  292.  
  293.     /* and put it back */
  294.  
  295.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  296.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  297.     intdos(&r, &r);        /* go fer it */
  298. }
  299.  
  300. rawoff()    /* put the HP150 keyboard into COOKED mode */
  301.  
  302. {
  303.     /* get the IO control info */
  304.  
  305.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  306.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  307.     intdos(&r, &r);        /* go fer it */
  308.  
  309.     r.h.dh = 0;        /* clear high byte for put */
  310.     r.h.dl &= 0xdf;        /* set raw bit */
  311.  
  312.     /* and put it back */
  313.  
  314.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  315.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  316.     intdos(&r, &r);        /* go fer it */
  317. }
  318.  
  319.  
  320. ckeyoff()    /* turn control-C trapping off */
  321.  
  322. {
  323.     r.h.ah = 0x33;    /* ctrl-break check */
  324.     r.h.al = 1;    /* set the state of the ctrl-break check */
  325.     r.h.dl = 0;    /* turn it off */
  326.     intdos(&r, &r);
  327. }
  328.  
  329. ckeyon()    /* turn control-C trapping on */
  330.  
  331. {
  332.     r.h.ah = 0x33;    /* ctrl-break check */
  333.     r.h.al = 1;    /* set the state of the ctrl-break check */
  334.     r.h.dl = 1;    /* turn it on */
  335.     intdos(&r, &r);
  336. }
  337.  
  338. agios(buf, len)    /* perform an AGIOS call */
  339.  
  340. char *buf;    /* sequence of bytes in command */
  341. int len;    /* length of command in bytes */
  342.  
  343. {
  344.     r.x.ax = 0x4403;    /* I/O ctrl write */
  345.     r.x.bx = 1;        /* console handle */
  346.     r.x.cx = len;        /* buffer length */
  347.     r.x.dx = (unsigned)buf;    /* buffer address */
  348.     return(intdos(&r, &r));    /* do it */
  349. }
  350.  
  351. keycon()    /* turn keycode mode on */
  352.  
  353. {
  354.     static char cmd[] = {43, 0, 1};
  355.  
  356.     return(agios(&cmd[0], 3));
  357. }
  358.  
  359. keycoff()    /* turn keycode mode off */
  360.  
  361. {
  362.     static char cmd[] = {43, 0, 0};
  363.  
  364.     return(agios(&cmd[0], 3));
  365. }
  366.  
  367. defkey()    /* change all special keys to intercept mode */
  368.  
  369. {
  370.     static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
  371.  
  372.     return(agios(&cmd[0], 6));
  373. }
  374.  
  375. undefkey()    /* change all special keys to intercept mode */
  376.  
  377. {
  378.     static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
  379.  
  380.     return(agios(&cmd[0], 6));
  381. }
  382.  
  383. dsplbls()    /* display the application softkey labels on the screen */
  384.  
  385. {
  386.     static char cmd[] = {11, 0};
  387.  
  388.     return(agios(&cmd[0], 2));
  389. }
  390.  
  391. #if    FLABEL
  392. fnclabel(f, n)        /* label a function key */
  393.  
  394. int f,n;    /* default flag, numeric argument */
  395.  
  396. {
  397.     register int status;    /* return status */
  398.     register int i;        /* loop index */
  399.     char lbl[17];    /* returned label contents */
  400.     /* AGIOS command buffer */
  401.     static char cmd[] = {8, 0, 1, 0, 7, 7, 7, 7, 10, 0, 10, 0};
  402.     /*                   code  key#  ptr to      top    bottom
  403.                                      label string  attribute */
  404.     union {        /* union to cast ptr into AGIOS arg string */
  405.         char *ptr;    /* pointer to arg string */
  406.         char cstr[4];
  407.     } ptru;
  408.  
  409.     /* must have a numeric argument */
  410.     if (f == FALSE) {
  411.         mlwrite("%Need function key number");
  412.         return(FALSE);
  413.     }
  414.  
  415.     /* and it must be a legal key number */
  416.     if (n < 1 || n > 8) {
  417.         mlwrite("%Function key number out of range");
  418.         return(FALSE);
  419.     }
  420.  
  421.     /* get the string to send */
  422.     status = mlreply("Label contents: ", &lbl[0], 17);
  423.     if (status != TRUE)
  424.         return(status);
  425.  
  426.     /* pad the label out */
  427.     for (i=0; i < 17; i++) {
  428.         if (lbl[i] == 0)
  429.             break;
  430.     }
  431.     for (; i < 16; i++)
  432.         lbl[i] = ' ';
  433.     lbl[16] = 0;
  434.  
  435.     /* set up the parameters */
  436.     cmd[2] = n;            /* function key number */
  437.     ptru.ptr = &lbl[0];        /* set up pointer to label string */
  438. force:    cmd[4] = ptru.cstr[0];
  439.     cmd[5] = ptru.cstr[1];
  440.     cmd[6] = ptru.cstr[2];
  441.     cmd[7] = ptru.cstr[3];
  442.  
  443.     /* and send it out */
  444.     agios(&cmd[0], 12);
  445.     return(TRUE);
  446. }
  447. #endif
  448. #else
  449.  
  450. h15hello()
  451.  
  452. {
  453. }
  454. #endif
  455.